package com.iworkh.spring.data.jdbc.tx.service;

import com.iworkh.spring.data.jdbc.tx.dao.BookDao;
import com.iworkh.spring.data.jdbc.tx.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Order service
 *
 * @author: iworkh-沐雨云楼
 * @date: 2019-12-20
 */
@Service
public class OrderService {

    @Autowired
    private BookDao bookDao;

    @Autowired
    private StudentDao studentDao;

    @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED, readOnly = false,
                   timeout = 30)
    public void makeAnOrder(String studnetId, String bookId, double price) {
        bookDao.sellOne(bookId);
        studentDao.consume(studnetId, price);
    }
}
